package com.suyang.syt.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.suyang.syt.auth.AuthClass;
import com.suyang.syt.model.dto.AjaxObj;
import com.suyang.syt.model.dto.PagerEasyUI;
import com.suyang.syt.model.dto.UserStoresDTO;
import com.suyang.syt.service.interfaces.UserStoresService;
import com.suyang.syt.util.EmptyUtil;
import com.suyang.syt.util.StringUtil;

@Controller
@RequestMapping("/admin/user/store")
@AuthClass("login")
public class AdminUserStoresController {

	@Autowired
	private UserStoresService userStoresService;

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String list(String userid, Model model) {
		if (EmptyUtil.isNotEmpty(userid)) {
			model.addAttribute("userid", userid);
		}
		return "user/store/list";
	}

	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ResponseBody
	public PagerEasyUI<UserStoresDTO> list(HttpServletRequest request, int page, int rows, String sort, String order, String userid) {
		try {
			String createDate1 = request.getParameter("createDate1");
			String createDate2 = request.getParameter("createDate2");
			String checkName = request.getParameter("checkName");
			String checkStatus = request.getParameter("checkStatus");
			return userStoresService.listByEasyUI(page, rows, sort, order, createDate1, createDate2, checkName, checkStatus, userid);
		} catch (Exception e) {
			return null;
		}
	}

	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	@ResponseBody
	public AjaxObj delete(HttpServletRequest request, String ids) {
		try {
			return userStoresService.deleteStores(ids);
		} catch (Exception e) {
			return new AjaxObj(0, StringUtil.ERROR_MSG);
		}
	}

	@RequestMapping(value = "/getObj", method = RequestMethod.POST)
	@ResponseBody
	public AjaxObj addGetObj(HttpServletRequest request, long objid, long status) {
		try {
			return userStoresService.getobj(objid, status);
		} catch (Exception e) {
			return new AjaxObj(0, StringUtil.ERROR_MSG);
		}
	}
}
